#include <avr/io.h>
#include "config.h"
#include "led.h"
#include "util.h"
/**
 * \file led.c
 * \brief Small set of test functions for controlling LEDs on a AT90USBKey
 * 
 *
 * \author Clecio Varjao and Leanne Ross
 * \date October 2007
 */

static char initialized=0; //!< Indicates whether the led was initialized or not

/*!
 * Turn the led \c mask ON ans wait for \c miliseconds to turn it off
 */
inline void blink_led_for(unsigned int mask, unsigned int miliseconds){
	enable_led(mask);	
	delay(miliseconds);
	disable_led(mask);
}
/*!
 * Turn the led \c mask ON ans wait for 100 miliseconds to turn it off
 */
inline void blink_led(unsigned int mask){
	blink_led_for(mask, 100);
}

/*!
 * Initialize the LED port
 */
inline void init_leds(void){
	if (!initialized){
		DDRD = 0xFF;
		PORTD = 0x00;
	}
}

/*!
 * Turn the led defined by \c mask ON
 */
inline void enable_led(unsigned int mask)
{
	PORTD |= mask;
}

/*!
 * Turn the led defined by \c mask OFF
 */
inline void disable_led(unsigned int mask){
	PORTD &= ~(mask);
}

/*!
 * Turn ALL leds OFF
 */
inline void disable_leds(void)
{
	PORTD = 0x00;
}
